﻿'========================================================================
'功能:
'作者:andy
'日期: 2011/3/16
'========================================================================
Imports System.Data
Partial Class WebForm_AssetCost
    Inherits BasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName


            If Not ChkProgramRight(1) Then '查詢
                Me.btnQuery.Visible = False
                Me.gvModelPrice.Visible = False
            End If

            If Not ChkProgramRight(2) Then '新增
                Me.btnInsert.Visible = False
                plInsert.Visible = False

            End If

            If Not ChkProgramRight(3) Then '編輯
                Me.gvModelPrice.Columns(0).Visible = False

            End If

            If Not ChkProgramRight(4) Then '刪除
                Me.gvModelPrice.Columns(1).Visible = False

            End If
        End If

    End Sub






    
    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        gvModelPrice.DataBind()
    End Sub

   
    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click

    End Sub

    Protected Sub ddlFactory_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFactory.SelectedIndexChanged
        gvModelPrice.DataBind()
    End Sub
    Function ChkData() As Boolean
        If txtModelIns.Text.Trim = "" Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("ModelRequire"))
            Return False
        End If
        Dim price1 As Double
        Try
            price1 = Double.Parse(txtPriceIns.Text)
        Catch ex As Exception
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errPrice"))
            Return False
        End Try
        If price1 <= 0 Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errPrice0"))

            Exit Function
        End If
        Dim bbl As AssetManage.BBL.ModelPriceBBL = New AssetManage.BBL.ModelPriceBBL()
        If bbl.ModelIsExist(txtModelIns.Text, ddlOAFactoryIns.SelectedValue, hiDBName.Value) Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("DataExist"))
            Return False
        End If

        Return True
    End Function
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If ChkData() = False Then
            mpIns.Show()
            Return
        End If

        dbModelPrice.Insert()
        txtModelIns.Text = ""
        txtPriceIns.Text = ""
        txtDescriptionIns.Text = ""
        gvModelPrice.DataBind()

    End Sub

    Protected Sub gvModelPrice_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvModelPrice.RowUpdating
        Dim price As String = CType(gvModelPrice.Rows(e.RowIndex).Cells(3).Controls(0), TextBox).Text
        Dim price1 As Double
        Try
            price1 = Double.Parse(price)
        Catch ex As Exception
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errPrice"))
            e.Cancel = True
            Exit Sub

        End Try

        If price1 <= 0 Then
            ShowMessageForAjax(btnSave, GetLocalResourceObject("errPrice0"))
            e.Cancel = True
            Exit Sub
        End If
    End Sub
End Class
